<?php
/**
 * 注册总控制器
 * 仲伟涛 2011-3
 */
class Resume_Page_Register extends Resume_Page_Abstract
{
    private $ucenterDb;
    public function validate(ME_Request $input, ME_Response $output)
    {
        return true;
    }
    public function loadDb(){
        $this->ucenterDb = Db_Ucenter::instance();
    }
    public function doDefault(ME_Request $input, ME_Response $output)
    {
        //获得登录状态
        $input->jumpLogin = false;
        $loginArr = Libs_UcUser::checkLogin($input,$output);
        if($loginArr && $loginArr['uid']){
            echo "您已经注册过了,,<a href='javascript:;' onclick='history.go(-1)'>返回&gt;&gt;</a>";
            exit;
        }
        $output->header = Resume_Plugin_Header::getHeader($input, $output);
        $output->footer = Resume_Plugin_Header::getFooter($input, $output);
        $output->setTemplate('Register');
    }

    /**
     * 执行登录
     *
     */
    public function doRegister(ME_Request $input, ME_Response $output){
        $userName  = trim($input->post("userName"));
        $passWord  = trim($input->post("passWord"));
        $passWord2 = trim($input->post("passWord2"));
        $trueName  = trim($input->post("trueName"));
        $email     = trim($input->post("email"));
        $sex       = (int)$input->post("sex");
        
        if($passWord != $passWord2){
            echo "两次密码输入不一致,<a href='javascript:;' onclick='history.go(-1)'>返回&gt;&gt;</a>";
            exit;
        }


        $paramArr  = array('username'=>$userName,'password'=>$passWord,'email'=>$email);
        $regResult = Libs_UcUser::userRegister($paramArr);
        if($regResult['uid'] > 0){
            $paramArr['uid'] = (int)$regResult['uid'];
            $paramArr['life'] = 86400 * 360;
            Libs_UcUser::setLoginStatus($paramArr);
        }
	if($input->cookie("redirect_url")){
		$redirect_url = $input->cookie("redirect_url"); 
		setcookie("redirect_url","",time()-3600,"/");
	}
        echo "注册成功,转入到简历页面...";
	if($redirect_url){
		echo '<script>window.location.href="'.$redirect_url.'"</script>';
	}else{
        	echo '<script>window.location.href="?c=MyResume"</script>';
	}
        exit;
        
    }
}
